#include <iostream>
#include "set"
#include <functional>
#include <string>
using namespace std;

class Student
{
public:
	int age;
	string name;
	Student(int age, string name)
	{
		this->age = age;
		this->name = name;
	}
};

//仿函数
struct funcStudent
{
	bool operator()(const Student &left, const Student &right)
	{
		if (left.age < right.age)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
};
//容器 集合set 元素唯一，自动排序 (默认从小到大)不能按照下标插入元素
//multiset中同一值可以出现多次。
void my_set()
{
	set<int> s; //从小到大
	//set<int, less<int>> s2; //从小到大
	set<int, greater<int>> s2;//从大到小
	for (int i = 0; i < 5; i++)
	{
		int tmp = rand();
		s.insert(tmp);
		s2.insert(tmp);
	}
	cout << "s:" << endl;
	for (set<int>::iterator it = s.begin(); it != s.end(); it++)
	{
		cout << *it << " ";
	}
	cout << "\n" << "s2:" << endl;
	for (set<int>::iterator it = s2.begin(); it != s2.end(); it++)
	{
		cout << *it << " ";
	}

	cout << endl;
	while (!(s.empty()))
	{
		cout << *(s.begin()) << " ";
		s.erase(s.begin());
	}
	cout << "大小:" << s.size() << endl;

}

//对象集合,排序，引入仿函数
void student_set()
{
	set<Student, funcStudent> s;
	Student s1(34, "张三");
	s.insert(s1);
	Student s2(32, "李四");
	s.insert(s2);
	Student s3(36, "王五");
	s.insert(s3);
	for (set<Student>::iterator it = s.begin(); it != s.end(); it++)
	{
		cout << it->age << "--" << it->name << "\n";
	}
}

//set的查找
void find_set()
{
	set<int> s;
	for (int i = 0; i < 10; i++)
	{
		s.insert(i);
	}
	set<int>::iterator it = s.find(5);
	cout << "查找5: " << *it << endl;//5

	set<int>::iterator it2 = s.lower_bound(5);
	cout << "lower_bound5: " << *it2 << endl;//5

	set<int>::iterator it3 = s.upper_bound(5);
	cout << "upper_bound5: " << *it3 << endl;//6

	pair<set<int>::iterator, set<int>::iterator> pa = s.equal_range(5);
	cout << "pair_first: " << *(pa.first) << endl;//5
	cout << "pair_second: " << *(pa.second) << endl;//6
}

void my_multiset()
{
	multiset<string> ms;
	ms.insert("hello");
	ms.insert("hello");
	ms.insert("world");
	for (multiset<string>::iterator it = ms.begin(); it != ms.end(); it++)
	{
		cout << *it << endl;
	}
}
int main8()
{
	//my_set();
	//student_set();
	//find_set();
	my_multiset();
	system("pause");
	return 0;
}